package com.wc.alorithm_blue_bridge._动态规划.线性DP.最大和;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2025/4/1 17:28
 * @description
 * https://www.lanqiao.cn/courses/46292/learning/?id=3455971&compatibility=false
 */
public class Main {
    /**
     * 思路：和登录台阶一样
     * 审题清晰好吧
     * 是 i -> i + 1 到 i + d(n - i)
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 10010, INF = 0x3f3f3f3f;
    static int[] d = new int[N], a = new int[N];
    static int[] f = new int[N];
    static int n;

    public static void main(String[] args) {
        n = sc.nextInt();
        d[1] = 1;
        // 唉筛求最小质因数
        for (int i = 2; i < N; i++) {
            if (d[i] != 0) continue;
            for (int j = i; j < N; j += i) {
                if (d[j] == 0) d[j] = i;
            }
        }
        for (int i = 1; i <= n; i++) a[i] = sc.nextInt();
        Arrays.fill(f, 1, n + 1, -INF);
        f[1] = a[1];
        for (int i = 1; i < n; i++) {
            for (int j = 1; j <= d[n - i]; j++) {
                f[i + j] = Math.max(f[i + j], f[i] + a[i + j]);
            }
        }
        out.println(f[n]);
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}

